//
//  DetailViewController.m
//  UI16.真.豆瓣
//
//  Created by dllo on 15/10/30.
//  Copyright © 2015年 Amydom. All rights reserved.
//

#import "DetailViewController.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
#import "DetailView.h"
#import "LoginViewController.h"

@interface DetailViewController ()
@property (nonatomic,retain)DetailView *detaiV;


@end


@implementation DetailViewController

-(void)dealloc{
   
    [super dealloc];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
 
    
    UIScrollView *scrollV = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.view addSubview:scrollV];
    [scrollV release];
    
    scrollV.contentSize = CGSizeMake(375, 1800);
    
    self.detaiV = [[DetailView alloc]init];
    
    [scrollV addSubview:self.detaiV];
    
    
    
    
    
    
    
    self.view.backgroundColor =[UIColor whiteColor];
    NSString *urlStr = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/searchmovie.php?movieId=%@",self.movieID];
    
    [AppTools getDataWithURL:urlStr Block:^(id result) {
        
        
        NSMutableDictionary *dic = result;
        NSLog(@"%@",dic);
        NSMutableDictionary *dic1 = [dic objectForKey:@"result"];
        
        NSString *name = [dic1 objectForKey:@"rating"];
        self.detaiV.gradeLabelG.text = name;
        
        NSString *rating = [dic1 objectForKey:@"rating_count"];
        NSString *str = [NSString stringWithFormat:@"(%@评论)",rating];
        self.detaiV.rating_countLabel.text =str ;
        
        NSString *time = [dic1 objectForKey:@"release_date"];
        self.detaiV.timeLabel.text = time;
        
        NSString *runtime = [dic1 objectForKey:@"runtime"];
        self.detaiV.runtimeLabel.text = runtime;
        
        NSString *country = [dic1 objectForKey:@"country"];
        self.detaiV.countryLabel.text = country;
        
        NSString *genres = [dic1 objectForKey:@"genres"];
        self.detaiV.moldLabel.text = genres;
        
        NSString *title = [dic1 objectForKey:@"title"];
        self.navigationItem.title = title;
        
        NSString *actors = [dic1 objectForKey:@"actors"];
        self.detaiV.particularWriteLabel.text = actors;
        self.detaiV.particularWriteLabel.numberOfLines = 0;
        [self.detaiV.particularWriteLabel sizeToFit];
        
        NSString *plot_simple = [dic1 objectForKey:@"plot_simple"];
        NSString *strP = [NSString stringWithFormat:@"  %@",plot_simple];
        self.detaiV.partPlotLabel.text = strP;
        self.detaiV.partPlotLabel.numberOfLines = 0;
        [self.detaiV.partPlotLabel sizeToFit];
        
#pragma mark -- scroll自适应高度
        CGFloat height = self.detaiV.partPlotLabel.frame.origin.y + self.detaiV.partPlotLabel.frame.size.height + 70;
        scrollV.contentSize = CGSizeMake(0, height);

        
        

        NSURL *url = [NSURL URLWithString:[dic1 objectForKey:@"poster"]];
        
        [self.detaiV.movieDetaImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"e8db9451737015bf9622f88a14cc9a40.jpg"]];
        
        
        
    }];
#pragma mark -- 取消图片渲染
    UIImage *leftImage = [UIImage imageNamed:@"btn_nav_back.png"];
    leftImage = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_share.png"];
    
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImage style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:@selector(RightAction:)];

    /*
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor redColor];
    button.frame = CGRectMake(150, 150, 50, 50);
    [button addTarget:self action:@selector(Vction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    */
    
}



- (void)leftButtonAction:(UIBarButtonItem *)btn{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}

- (void)RightAction:(UIBarButtonItem *)btn{
    
    LoginViewController *logVC = [[LoginViewController alloc]init];
    [self.navigationController pushViewController:logVC animated:YES];
    
    
}




- (void)Vction:(UIButton *)btn {
#pragma mark   清除缓存
    [[SDImageCache sharedImageCache]clearDisk];
    
    
#pragma mark    获取SDWebImage缓存图片大小
  NSUInteger size = [[SDImageCache sharedImageCache]getSize];
    float cacheSize = size / 1024.0 / 1024.0;
    NSLog(@"%f",cacheSize);
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
